package utils

import (
	"errors"
	"github.com/flyaways/pool"
	"google.golang.org/grpc"
	"sync"
)

type RpcClientPool struct {
	m sync.Map
	servername string
}

func (p *RpcClientPool) Store(sevicename string,conn *grpc.ClientConn)   {
	p.m.Store(sevicename,conn)
}
func (p *RpcClientPool) StorePool(sevicename string,pool *pool.GRPCPool)   {
	p.m.Store(sevicename,pool)
}
func (p *RpcClientPool) Load(target string) (*grpc.ClientConn,error)  {
	if i,ok:= p.m.Load(target);ok{
		return i.(*grpc.ClientConn),nil
	}
	return nil,errors.New("不存在 servicename")
}
func (p *RpcClientPool) LoadPool(target string) (*pool.GRPCPool,error)  {
	if i,ok:= p.m.Load(target);ok{
		return i.(*pool.GRPCPool),nil
	}
	return nil,errors.New("不存在 servicename")
}
